﻿#ifndef MEASURELINE_H
#define MEASURELINE_H

#include "MeasureElement.h"
namespace Qly {

class MeasureDataSet;

/**
 * @brief The MeasureLine class 两点之间距离。
 *                  m_results_um[1] 存的是两点间 X 方向距离。
 *                  m_results_um[2] 存的是两点间 Y 方向距离。
 *                  m_results_um[0] 存的是两点间 直线距离。
 *
 *                  textTemplate 支持 @lengthX_um, @lengthX_mm, @lengthX, @lengthY_um, @lengthY_mm, @lengthY,
 *                                   @length_um, @length_mm, @length, @unitX,  @unitY, @unit, @id 13 个关键字
 */
class MeasureLine : public MeasureElement
{
    friend MeasureDataSet;
public:
    MeasureLine(MeasureDataSet *parent = nullptr);
    ~MeasureLine() {}
    QString name() Q_DECL_OVERRIDE {return u8"点到点距离";}
private:

    bool testMoveState(QPointF point_pix);
    void cancelMoveState();
    int mouseLButtonPress(QPointF point_pix, QPointF point_um) Q_DECL_OVERRIDE;
    int mouseMove(QPointF point_pix, QPointF point_um) Q_DECL_OVERRIDE;

    void setStartPoint(QPointF point_pix, QPointF point_um);// 设置第一个点
    void setTempEndPoint(QPointF point_pix, QPointF point_um);
    void setEndPoint(QPointF point_pix, QPointF point_um); // 设置第二个点
    bool adjust(QPointF offset_pix, QPointF offset_um);

    void compute(void) Q_DECL_OVERRIDE; //计算图元的位置，还有长度结果
    void updateText(bool updatePosition = true) Q_DECL_OVERRIDE;
    void paint( QPainter &painter ) Q_DECL_OVERRIDE; //画方法
    void buildBar();// 生成直线两端的小线段
static double barLength_inter_pix;
static double barLength_final_pix;
    // 为了出现标尺的图形，还得加上四个标尺的坐标。
    QPointF m_line1_start;
    QPointF m_line1_end;
    QPointF m_line2_start;
    QPointF m_line2_end;

    // 下面两个变量记录直线的角度，用来加快计算。
    double m_cos_theta = 0.0;
    double m_sin_theta = 0.0;

    int m_adjust = 0;
    QPointF m_tempPoint_pix;
    QPointF m_tempPoint_um;

};

inline void MeasureLine::cancelMoveState()
{
    m_adjust = 0;
}

}


#endif // MEASURELINE_H
